Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
ml-distance
Advanced tools
The ml-distance npm package provides a collection of functions to calculate various types of distances between vectors. It is useful for tasks in machine learning, data analysis, and other fields where measuring similarity or dissimilarity between data points is important.
Euclidean Distance
Calculates the Euclidean distance between two vectors. This is the straight-line distance in Euclidean space.
const distance = require('ml-distance');
const euclidean = distance.euclidean([1, 2], [4, 6]);
console.log(euclidean); // Output: 5
Manhattan Distance
Calculates the Manhattan distance between two vectors. This is the sum of the absolute differences of their Cartesian coordinates.
const distance = require('ml-distance');
const manhattan = distance.manhattan([1, 2], [4, 6]);
console.log(manhattan); // Output: 7
Cosine Similarity
Calculates the cosine similarity between two vectors. This measures the cosine of the angle between them, which is useful for determining how similar two vectors are.
const distance = require('ml-distance');
const cosine = distance.cosine([1, 2], [4, 6]);
console.log(cosine); // Output: 0.9838699100999074
Jaccard Index
Calculates the Jaccard index between two sets. This is the size of the intersection divided by the size of the union of the sets.
const distance = require('ml-distance');
const jaccard = distance.jaccard([1, 2, 3], [2, 3, 4]);
console.log(jaccard); // Output: 0.5
The compute-distance package provides a variety of distance metrics similar to ml-distance, including Euclidean, Manhattan, and Chebyshev distances. It is a good alternative for users looking for a different implementation or additional distance metrics.
The ml-matrix package offers a comprehensive set of matrix operations, including distance calculations. It is more feature-rich compared to ml-distance, providing additional functionalities for matrix manipulation and linear algebra.
The distance package focuses on string distance metrics like Levenshtein, Jaro-Winkler, and Hamming distances. While it overlaps with ml-distance in some areas, it is more specialized in string comparison.
Distance functions to compare vectors
$ npm install ml-distance
Returns the euclidean distance between vectors p and q
Returns the city block distance between vectors p and q
Returns the Minkowski distance between vectors p and q for order d
Returns the Chebyshev distance between vectors p and q
Returns the Sørensen distance between vectors p and q
Returns the Gower distance between vectors p and q
Returns the Soergel distance between vectors p and q
Returns the Kulczynski distance between vectors p and q
Returns the Canberra distance between vectors p and q
Returns the Lorentzian distance between vectors p and q
Returns the Intersection distance between vectors p and q
Returns the Intersection similarity between vectors p and q
Returns the Wave Hedges distance between vectors p and q
Returns the Czekanowski distance between vectors p and q
Returns the Czekanowski similarity between vectors p and q
Returns the Motyka distance between vectors p and q
Returns the Motyka similarity between vectors p and q
Returns the Kulczynski similarity between vectors p and q
Returns the Ruzicka similarity between vectors p and q
Returns the Tanimoto distance between vectors p and q, and accepts the bitVector use, see the test case for an example
Returns the Inner Product similarity between vectors p and q
Returns the Harmonic mean similarity between vectors p and q
Returns the Cosine similarity between vectors p and q
Returns the Kumar-Hassebrook similarity between vectors p and q
Returns the Jaccard distance between vectors p and q
Returns the Jaccard similarity between vectors p and q
Returns the Dice distance between vectors p and q
Returns the Dice similarity between vectors p and q
Returns the Fidelity similarity between vectors p and q
Returns the Bhattacharyya distance between vectors p and q
Returns the Hellinger distance between vectors p and q
Returns the Matusita distance between vectors p and q
Returns the Squared-chord distance between vectors p and q
Returns the Squared-chord similarity between vectors p and q
Returns the squared euclidean distance between vectors p and q
Returns the Pearson distance between vectors p and q
Returns the Neyman distance between vectors p and q
Returns the Squared distance between vectors p and q
Returns the Probabilistic Symmetric distance between vectors p and q
Returns the Divergence distance between vectors p and q
Returns the Clark distance between vectors p and q
Returns the Additive Symmetric distance between vectors p and q
Returns the Kullback-Leibler distance between vectors p and q
Returns the Jeffreys distance between vectors p and q
Returns the K divergence distance between vectors p and q
Returns the Topsøe distance between vectors p and q
Returns the Jensen-Shannon distance between vectors p and q
Returns the Jensen difference distance between vectors p and q
Returns the Taneja distance between vectors p and q
Returns the Kumar-Johnson distance between vectors p and q
Returns the average of city block and Chebyshev distances between vectors p and q
Returns the tree similarity between two spectra in the format {'x':Array,'y':Array}
options
calc
Calculates the tree similarity
createTree
Creates the tree based in the input dataset
A new metric should normally be in its own file in the src/dist directory. There should be a corresponding test file in test/dist.
The metric should be then added in the exports of src/index.js with a relatively small but understandable name (use camelCase).
It should also be added to this README with either a link to the formula or an inline description.
$ npm install
$ npm test
FAQs
Distance and similarity functions to compare vectors
The npm package ml-distance receives a total of 126,494 weekly downloads. As such, ml-distance popularity was classified as popular.
We found that ml-distance demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.